/**
 * 检查用户登入状态
 */
import useUserStore from '@/store/index.js'
import {storeToRefs} from "pinia";
import axios from "axios";
import router from "@/router/index.js";
const checkLoginStatus =  (success,failed) => {
const store = useUserStore()

    const {token,username}= storeToRefs(store)
    if (token.value){
        //如果有token，为axios的请求添加请求头
        axios.defaults.headers['Authorization'] = `Bearer ${token.value}`
        if (success){
            success()}
        }else {
        //如果没有token（未登入），跳转到登录页面
        if (failed){
            failed()

        }

    }
}
export default checkLoginStatus